package org.giovanolli.mumi.dao.impl;

import org.apache.commons.lang.StringUtils;
import org.giovanolli.mumi.dao.SpecialityDao;
import org.giovanolli.mumi.entities.Speciality;
import org.giovanolli.mumi.entities.filter.EntityFilter;
import org.giovanolli.mumi.entities.filter.SpecialityFilter;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

// TODO: Auto-generated Javadoc
/**
 * The Class SpecialityDaoImpl.
 */
@Repository("specialityDao")
public class SpecialityDaoImpl extends HibernateDao<Speciality> implements SpecialityDao {

	@Override
	protected DetachedCriteria fillCriteria(EntityFilter<Speciality> filter, DetachedCriteria criteria) {
		final SpecialityFilter entityFilter = (SpecialityFilter) filter;

		if (filter != null) {
			if (StringUtils.isNotBlank(entityFilter.getName())) {
				criteria.add(Restrictions.ilike("name", entityFilter.getName(), MatchMode.ANYWHERE));
			}
		}
		return criteria;
	}

}
